import { Component, OnInit } from '@angular/core';
import { STColumn, STChange, STPage } from '@delon/abc';
import { ActivatedRoute, Router } from '@angular/router';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';

@Component({
  selector: 'app-detail',
  templateUrl: './detail.component.html',
  styles: [],
})
export class DetailComponent implements OnInit {
  users: any[] = [];
  listOfData = [
    {
      key: '1',
      first: '个人信息',
      second: '姓名',
      detail: '蔡成功',
    },
    {
      key: '2',
      first: '个人信息',
      second: '曾用名',
      detail: '无',
    },
    {
      key: '3',
      first: '个人信息',
      second: '性别',
      detail: '男',
    },
    {
      key: '4',
      first: '个人信息',
      second: '年龄',
      detail: '48',
    },
    {
      key: '5',
      first: '个人信息',
      second: '民族',
      detail: '汉',
    },
    {
      key: '6',
      first: '个人信息',
      second: '学历',
      detail: '本科',
    },
    {
      key: '7',
      first: '个人信息',
      second: '职业',
      detail: '大风厂董事长',
    },
    {
      key: '8',
      first: '个人信息',
      second: '就业单位',
      detail: '京州市大风厂',
    },
    {
      key: '9',
      first: '个人信息',
      second: '身份证号',
      detail: '140322196909042951',
    },
    {
      key: '10',
      first: '个人信息',
      second: '生日',
      detail: '1969-09-04',
    },
    {
      key: '11',
      first: '个人信息',
      second: '婚姻情况',
      detail: '已婚',
    },
    {
      key: '12',
      first: '个人信息',
      second: '宗教信仰',
      detail: '无',
    },
    {
      key: '13',
      first: '个人信息',
      second: '驾驶证信息',
      detail: '426351196909042951',
    },
    {
      key: '14',
      first: '个人信息',
      second: '是否有案底',
      detail: '无',
    },
    {
      key: '15',
      first: '个人信息',
      second: '户口所在地',
      detail: '汉东省东山市水口县罗田村',
    },
    {
      key: '16',
      first: '个人信息',
      second: '当前住址',
      detail: '汉东省京州市幸福花园3栋502',
    },
    {
      key: '17',
      first: '个人信息',
      second: '人口类别',
      detail: '常驻人口',
    },
    {
      key: '18',
      first: '物理属性',
      second: '身高',
      detail: '174',
    },
    {
      key: '19',
      first: '物理属性',
      second: '体重',
      detail: '80',
    },
    {
      key: '20',
      first: '物理属性',
      second: '肤色',
      detail: '黄色',
    },
    {
      key: '21',
      first: '物理属性',
      second: '血型',
      detail: 'B型',
    },
    {
      key: '22',
      first: '物理属性',
      second: '是否残疾',
      detail: '否',
    },
    {
      key: '23',
      first: '物理属性',
      second: '是否纹身',
      detail: '否',
    },
    {
      key: '24',
      first: '物理属性',
      second: '头发颜色',
      detail: '黑色',
    },
    {
      key: '25',
      first: '社交属性',
      second: '电话号码',
      detail: '18600838383',
    },
    {
      key: '26',
      first: '社交属性',
      second: 'QQ号码',
      detail: '12345678',
    },
    {
      key: '27',
      first: '社交属性',
      second: '微信账号',
      detail: 'caichenggong_wechat',
    },
    {
      key: '28',
      first: '社交属性',
      second: '抖音账号',
      detail: 'caichenggong_douyin',
    },
    {
      key: '29',
      first: '社交属性',
      second: '淘宝账号',
      detail: 'caichenggong_taobao',
    },
    {
      key: '30',
      first: '社交属性',
      second: '美团账号',
      detail: 'caichenggong_meituan',
    },
    {
      key: '31',
      first: '社交属性',
      second: '大众点评账号,',
      detail: 'caichenggong_dianiping',
    },
    {
      key: '32',
      first: '社交属性',
      second: '饿了么账号',
      detail: 'caichenggong_element',
    },
  ];

  imageArray = [
    { url: './assets/蔡成功_avatar.png' },
    { url: './assets/蔡成功_avatar1.png' },
    { url: './assets/蔡成功_avatar2.png' },
    { url: './assets/蔡成功_avatar3.png' },
  ];

  columns: STColumn[] = [
    {
      title: '编号',
      index: 'id',
      type: 'checkbox',
      selections: [
        {
          text: '联系事件数量小于10次',
          select: data => data.forEach(item => (item.checked = item.age < 10)),
        },
        {
          text: '联系事件数量大于10次',
          select: data => data.forEach(item => (item.checked = item.age >= 10)),
        },
      ],
    },
    {
      title: '姓名',
      index: 'name',
      sort: {
        compare: (a, b) => a.name.length - b.name.length,
      },
      filter: {
        type: 'keyword',
        fn: (filter, record) => !filter.value || record.name.indexOf(filter.value) !== -1,
      },
    },
    {
      title: '联系事件数量',
      index: 'age',
      sort: {
        compare: (a, b) => a.age - b.age,
      },
      filter: {
        menus: [
          { text: '10次以下', value: [0, 10] },
          { text: '10-25次', value: [10, 25] },
          { text: '25次以上', value: [25, 100] },
        ],
        fn: (filter, record) => record.age >= filter.value[0] && record.age <= filter.value[1],
        multiple: false,
      },
    },
    {
      title: '状态',
      type: 'badge',
      index: 'status',
      badge: {
        1: { text: '最近1天内有联系', color: 'success' },
        2: { text: '最近3天内有联系', color: 'error' },
        3: { text: '最近1年内无联系', color: 'processing' },
        4: { text: '最近半年内有联系', color: 'default' },
        5: { text: '最近1月内有联系', color: 'warning' },
      },
    },
  ];

  stpage: STPage = {
    show: false,
  };

  peopleRelationEntryArray: string[];

  eventListOfData = [
    {
      number: 1,
      name: '高小琴',
      type: '通话事件',
      content: '通话1分28秒',
    },
    {
      number: 2,
      name: '高小琴',
      type: '金融事件',
      content: '汇款：100万',
    },
    {
      number: 3,
      name: '侯亮平',
      type: '短信事件',
      content: '短信内容：兄弟，我摊上大事了',
    },
  ];

  documentListOfData = [
    {
      number: 1,
      name: '通话记录',
      content: '通话1分28秒',
    },
    {
      number: 2,
      name: '转账记录',
      content: '汇款：100万',
    },
    {
      number: 3,
      name: '信令查询记录',
      content: '短信内容：兄弟，我摊上大事了',
    },
  ];

  constructor(private router: Router) {}

  ngOnInit() {
    this.peopleRelationEntryArray = [
      '高小琴',
      '丁义诊',
      '高育良',
      '祁同伟',
      '侯亮平',
      '沙瑞金',
      '陆亦可',
      '吴惠芬',
      '钟小艾',
      '季昌明',
      '赵东来',
    ];
    of(
      Array(10)
        .fill({})
        .map((_item: any, idx: number) => {
          return {
            id: idx + 1,
            // name: `name ${idx + 1}`,
            name: this.peopleRelationEntryArray[idx],
            age: Math.ceil(Math.random() * 10) + 20,
            status: Math.floor(Math.random() * 5) + 1,
          };
        }),
    )
      .pipe(delay(500))
      .subscribe(res => (this.users = res));
  }

  toggalTable(index) {
    // console.log(index);
    switch (index) {
      case 0:
        return true;
      case 17:
        return true;
      case 24:
        return true;
      default:
        return false;
    }
  }

  setRowspan(index) {
    // console.log(index);
    switch (index) {
      case 0:
        return 17;
      case 17:
        return 7;
      case 24:
        return 8;
      default:
        return 1;
    }
  }
  change(e: STChange) {
    console.log(e);
  }

  toRelation() {
    this.router.navigate(['/relation']);
  }
}
